package civaid.datamodel;

import java.util.Collection;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class Session {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;

	@Persistent(mappedBy = "session")
	private Collection<Civilization> civilizations;

	@Persistent
	private String sessionId;

	@Persistent
	private String password;

	@Persistent
	public Date created;

	@NotPersistent
	private transient boolean newSession=false; 
	
	public Session(String sessionId) {
		this.sessionId = sessionId;
		this.created = new Date();
	}

	public void markAsNew() {
		newSession = true;
	}
	
	public boolean isNew() {
		return newSession;
	}
	
	public Key getKey() {
		return key;
	}

	public String getSessionId() {
		return sessionId;
	}

	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Collection<Civilization> getCivilizations() {
		return civilizations;
	}

}
